package mil.af.amc.adpetracker.web.actions.struts1.MaintenanceEntry;

import mil.af.amc.adpetracker.service.MaintenanceService;
import mil.af.amc.adpetracker.web.actions.struts1.AbstractAction;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Please Fill in this Javadoc
 *
 * @author TSgt Jason Ferguson
 */

public class CreateMaintenanceEntryAction extends AbstractAction {

    private static final Log log = LogFactory.getLog(CreateMaintenanceEntryAction.class);

    private MaintenanceService maintenanceService;

    public void setMaintenanceService(MaintenanceService maintenanceService) {
        this.maintenanceService = maintenanceService;
    }

    @SuppressWarnings({"unchecked"})
    @Override
    public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {

        int itemId = Integer.parseInt(httpServletRequest.getParameter("itemId"));
        DynaActionForm form = (DynaActionForm) actionForm;
        Map itemMap = form.getMap();
        itemMap.put("itemId", itemId);

        maintenanceService.create(itemMap);

        return actionMapping.findForward("success");

    }
}
